function ajax( { 
  url,
  data = {},
  method = "get"
} ){
  let str = "";
  for(let i in data){
    str += `${i}=${data[i]}&`;
  }
  str = str.slice(0, -1);
  if(method === "get"){
    url += "?" + str;
  }
  const xhr = new XMLHttpRequest();
  xhr.open(method, url);
  if(method === "post"){
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.send(str);
  }else{
    xhr.send();
  }
  return new Promise((resolve, reject)=>{
    xhr.onload = function(){
      if(xhr.status === 200){
        resolve( xhr.responseText );
      }else{
        reject( xhr.status );
      }
    }
  })
}